﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using ClassLibrary.DAO;

public partial class Admin_UserControl_UcTax_invoice : System.Web.UI.UserControl
{
    TblJobsDAO JobsDAO = new TblJobsDAO(Global.CONNECTION_STRING);
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            LoadTaxInoice();
            lbDateIn.Text = DateTime.Now.ToString("dd/MM/yyyy");       
            //int moth = Convert.ToInt32(DateTime.Now.Month);
            //int moth_next = moth + 3;           
            //lbDateOut.Text = DateTime.Now.Day + "/" + moth_next + "/" + DateTime.Now.Year;
            lbDateOut.Text = DateTime.Now.AddMonths(3).ToString("dd/MM/yyyy");
        }
    }

    private void LoadTaxInoice()
    {
        string id = Request.QueryString["id"];
        DataTable dt = JobsDAO.reportJob1(Convert.ToInt32(id));
        foreach (DataRow dr in dt.Rows)
        {
            lbcustomerID.Text = dr["CustomerIndex"].ToString();
            lbDateInvoice.Text = DateTime.Now.ToString("dd/MM/yyyy");
            lbJobID.Text = dr["JobID"].ToString();
            lblCusName.Text = dr["CustomerFullname"].ToString();
            lbCompany.Text = dr["Companyname"].ToString();
            lbAdress.Text = dr["postalsuburb"].ToString();
            lbMobile.Text = dr["phonemobile"].ToString();


            lblManuFactuer.Text = dr["Manufacturer"].ToString();

            lblModel.Text = dr["Model"].ToString();
            lblIMEI.Text = dr["IMEINo"].ToString();
            lblAccssories.Text = dr["AccessoriesWithPhone"].ToString();
            lblFauls.Text = dr["FaultDescription"].ToString();
            if (dr["LoanFee"].ToString() == "")
            {
                //lbCostLoanPhone.Text = "$0.00";
                lbLoanPhoneFee.Visible = false;
                lbCostLoanPhone.Visible = false;
                lbAreadyPaid.Visible = false;
            }
            else
            {
                 lbCostLoanPhone.Text = decimal.Parse(dr["LoanFee"].ToString()).ToString("c");
            }

            if (dr["AmountDeposited"].ToString() == "")
            {
                //lbDeposit.Text = "$0.00";
                lbDeposit.Visible = false;
                lbDepositOnLoanPhone.Visible = false;
                lbToBeRefunded.Visible = false;
            }
            else
            {
                lbDeposit.Text = decimal.Parse(dr["AmountDeposited"].ToString()).ToString("c");
            }
           
            //lbDateIn.Text = Convert.ToDateTime(dr["DateBook"].ToString()).ToShortDateString();
           // lbDateOut.Text = Convert.ToDateTime(dr["DateCompleted"].ToString()).ToShortDateString();

            //lbServiceCharge.Text = dr["AmountQuoted"].ToString();

            decimal AmountQuoted;
            AmountQuoted = Decimal.Parse(dr["AmountQuoted"].ToString());
            lbServiceCharge.Text = AmountQuoted.ToString("c");

            decimal AmountDeposit;
            decimal InvoidAmount;
    
            if (dr["AmountDeposited"].ToString() != "")
            {
                //lbInvoidAmount.Text = AmountQuoted 
                AmountDeposit = decimal.Parse(dr["AmountDeposited"].ToString());
                InvoidAmount = AmountQuoted - AmountDeposit;
                lbInvoidAmount.Text = InvoidAmount.ToString("c");
            }
            else
            {
                lbInvoidAmount.Text = AmountQuoted.ToString("c");
            }

            lbPartUsed.Text = dr["PartDescription"].ToString();
        }

        DataTable dt1 = JobsDAO.LoadJobNote_ID(Global.ConvertToInt(id));
        foreach (DataRow dr in dt1.Rows)
        {
            lbNoteJobStatus.Text = dr["Notes"].ToString();
        }

    }
}
